package com.example.learn.hwod;

import java.util.Scanner;

public class _28并查集 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[][] msgs = new int[m][3];
        for (int i = 0; i < m; i++) {
            msgs[i][0] = sc.nextInt();
            msgs[i][1] = sc.nextInt();
            msgs[i][2] = sc.nextInt();
        }

        getResult(msgs, n, m);

    }

    private static void getResult(int[][] msgs, int n, int m) {
        if (n < 1 || n >= 100000 || m < 1 || m >= 100000) {
            System.out.println("NULL");
            return;
        }

        UnionFindSet ufs = new UnionFindSet(n + 1);
        for (int[] msg : msgs) {
            int a = msg[0];
            int b = msg[1];
            int c = msg[2];
            if (a < 1 || a > n || b < 1 || b > n) {
                // 当前行 a 或 b 的标号小于 1 或者大于 n 时，输出字符串‘da pian zi‘
                System.out.println("da pian zi");
                continue;
            }
            if (c==0) {
                ufs.union(a, b);
            }else if (c==1) {
                System.out.println(ufs.find(a) == ufs.find(b) ? "we are a team" : "we are not a team");
            }else {
                // c 为其他值，输出字符串‘da pian zi‘
                System.out.println("da pian zi");
            }

        }

    }

    public static class UnionFindSet{
        int[] fa;
        public UnionFindSet(int n){
            fa = new int[n];
            for (int i = 0; i < n; i++){
                fa[i] = i;
            }
        }

        public int find(int x){
            if (this.fa[x]!=x) {
                return this.fa[x]=this.find(this.fa[x]);
            }
            return x;
        }
        public void union(int x, int y){
            int x_fa = this.find(x);
            int y_fa = this.find(y);

            if (x_fa != y_fa) {
                this.fa[y_fa] = x_fa;
            }
        }
    }
}
